#pragma once
#include <SFML/Graphics.hpp>

struct Rocket {
	sf::Texture rocketTextures, hitboxTextures;
	sf::Sprite rocketSprite, rocketHitbox1, rocketHitbox2;
	float s; //ñêîðîñò ðîêåòû
	double currentFrame;
    Rocket(){
        s = 0.13f;
        currentFrame = 0;
		rocketTextures.loadFromFile("Image/rocket.png");
		rocketSprite.setTexture(rocketTextures);
		rocketSprite.scale(sf::Vector2f(4, 4));// ÌÀñøòàáèðîâàíèå ðàêåòû
		rocketSprite.setTextureRect(sf::IntRect(0, 0, 50, 40));
		rocketSprite.setPosition(0, 200);

		rocketHitbox1.setTexture(hitboxTextures);
		rocketHitbox1.setColor(sf::Color(255, 0, 0));
		rocketHitbox1.scale(sf::Vector2f(4, 4));
		rocketHitbox1.setTextureRect(sf::IntRect(0, 0, 36, 18));
		rocketHitbox1.setPosition(48, 240);

		rocketHitbox2.setTexture(hitboxTextures);
		rocketHitbox2.setColor(sf::Color(255, 0, 0));
		rocketHitbox2.scale(sf::Vector2f(3, 3));
		rocketHitbox2.setTextureRect(sf::IntRect(0, 0, 50, 9));
		rocketHitbox2.setPosition(110, 200);
		rocketHitbox2.rotate(90.f);
	}

	void update(float time, sf::Vector2f pos) {

		// àíèìàöèÿ è óïðàâëåíèå ðàêåòû
		currentFrame += 0.0009 * (double)time;

		if (currentFrame > 2) currentFrame = 0;
		rocketSprite.setTextureRect(sf::IntRect(0, 42 * int(currentFrame), 50, 38));

		if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || (sf::Keyboard::isKeyPressed(sf::Keyboard::W)))) {


			rocketSprite.move(0, -s * time);
			rocketHitbox1.move(0, -s * time);
			rocketHitbox2.move(0, -s * time);
			pos = rocketSprite.getPosition();
			if (pos.y < -70) {
				rocketSprite.setPosition(pos.x, 1010);
				pos = rocketHitbox1.getPosition();
				rocketHitbox1.setPosition(pos.x, 1050);
				pos = rocketHitbox2.getPosition();
				rocketHitbox2.setPosition(pos.x, 1010);
			}


		}
		if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || (sf::Keyboard::isKeyPressed(sf::Keyboard::S)))) {

			rocketSprite.move(0, s * time);
			rocketHitbox1.move(0, s * time);
			rocketHitbox2.move(0, s * time);
			pos = rocketSprite.getPosition();
			if (pos.y > 1020) {
				rocketSprite.setPosition(pos.x, -70);
				pos = rocketHitbox1.getPosition();
				rocketHitbox1.setPosition(pos.x, -30);
				pos = rocketHitbox2.getPosition();
				rocketHitbox2.setPosition(pos.x, -70);
			}
		}
		if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || (sf::Keyboard::isKeyPressed(sf::Keyboard::A)))) {

			rocketSprite.move(-s * time, 0);
			rocketHitbox1.move(-s * time, 0);
			rocketHitbox2.move(-s * time, 0);
			pos = rocketSprite.getPosition();
			if (pos.x < -15) {
				rocketSprite.setPosition(-15, pos.y);
				pos = rocketHitbox1.getPosition();
				rocketHitbox1.setPosition(33, pos.y);
				pos = rocketHitbox2.getPosition();
				rocketHitbox2.setPosition(96, pos.y);
			}
		}
		if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || (sf::Keyboard::isKeyPressed(sf::Keyboard::D)))) {

			rocketSprite.move(s * time, 0);
			rocketHitbox1.move(s * time, 0);
			rocketHitbox2.move(s * time, 0);
			pos = rocketSprite.getPosition();
			if (pos.x > 1720) {
				rocketSprite.setPosition(1720, pos.y);
				pos = rocketHitbox1.getPosition();
				rocketHitbox1.setPosition(1768, pos.y);
				pos = rocketHitbox2.getPosition();
				rocketHitbox2.setPosition(1830, pos.y);
				//комментарий
			}

		}
	}
 
};

